<template>
  <div>
    <div class="head">
      <div class="input">
        <span>培训编号：</span>
        <el-input v-model="queryData.code" placeholder="请输入培训编号" />
      </div>
      <div class="input">
        <span>培训名称：</span>
        <el-input v-model="queryData.plan_name" placeholder="请输入培训名称" />
      </div>
      <div class="input">
        <span>状态：</span>
        <el-select v-model="queryData.time_status" placeholder="请选择">
          <el-option label="未开始" :value="0">未开始</el-option>
          <el-option label="进行中" :value="1">进行中</el-option>
          <el-option label="已过期" :value="2">已过期</el-option>
        </el-select>
      </div>
      <div class="input">
        <span>培训类型：</span>
        <el-cascader
          :options="options2"
          v-model="queryData.type_id"
          :props="{ multiple: false, checkStrictly: true }"
          clearable
        ></el-cascader>
      </div>
      <div class="input">
        <span>时间：</span>
        <el-date-picker
          v-model="queryData.date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
      <el-button type="primary" class="btn" @click="search">查询</el-button>
      <el-button type="primary" class="btn" @click="reset">重置</el-button>
    </div>
    <div class="box">
      <el-table
        :data="tableData"
        border
        v-loading="isTableLoading"
        empty-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
        style="width: 100%"
      >
        <el-table-column fixed type="index" align="center" label="序号" width="50" />
        <el-table-column prop="code" align="center" label="培训编号" min-width="160" />
        <el-table-column prop="plan_name" align="center" label="培训名称" min-width="180" />
        <el-table-column prop="type_name" align="center" label="培训类型" width="140">
        </el-table-column>
        <el-table-column
          prop="plan_type_name"
          align="center"
          show-overflow-tooltip
          label="岗位类型"
          min-width="140"
        >
          <template #default="scope">
            <p v-if="scope.row.plan_type==1">内部培训</p>
            <p v-else-if="scope.row.plan_type==2">外部培训</p>
          </template>
        </el-table-column>
        <el-table-column prop="date" align="center" label="培训有效期" min-width="180">
          <template #default="scope">
            {{ scope.row.start_time + ' 至 ' + scope.row.end_time }}
          </template>
        </el-table-column>
        <el-table-column prop="status" align="center" label="状态" width="100">
          <template #default="scope">
            {{ scope.row.time_status == 0 ? '未开始' : (scope.row.time_status == 1 ? '进行中' : '已过期') }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" align="center" prop="action" label="操作" width="200">
          <template #default="scope">
            <div class="action">
              <span @click="course(scope)">课程列表</span>
              <span @click="student(scope)">学员列表</span>
              <!--<span >查看</span>-->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <el-pagination
          style="margin-top: 5px"
          @size-change="search"
          @current-change="search"
          :current-page.sync="queryData.page"
          :page-size.sync="queryData.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>

    <course-list ref="course" :type-list="options2"/>
    <staff-list ref="staff"/>
  </div>
</template>

<script>
import request from '@/libs/request';
import courseList from './courseList.vue'
import staffList from './staffList.vue'

export default {
  name: 'cultivate',
  components: {
    courseList, staffList
  },
  data() {
    return {
      queryData: {
        code: '',
        plan_name: '',
        time_status: '',
        type_id: '',
        date: [],
        page: 1,
        size: 10,
      },
      total: 0,
      isTableLoading: false,
      tableData: [],
      dialogVisible: false,
      options2: [],
      isShowTest: false,
    };
  },
  computed: {},
  created() {},
  mounted() {
    this.getInfo()
    this.getList();
  },
  methods: {
    getInfo() {
      request({
        url: '/plan/index/info',
        method: 'post'
      }).then(res => {
        this.options2 = res.data.type_list;
      })
    },
    search(d) {
      if (typeof d == 'number') {
        this.queryData.page = d;
      } else {
        this.queryData.page = 1;
      }
      this.getList();
    },
    reset() {
      this.queryData.plan_name = '';
      this.queryData.time_status = '';
      this.queryData.code = '';
      this.queryData.type_id = '';
      this.queryData.date = [];
      this.search();
    },
    course(item) {
      this.$refs.course.showModal(item.row.id)
    },
    student(item) {
      this.$refs.staff.showModal(item.row.id)
    },
    getList() {
      this.isTableLoading = true;
      request({
        url: '/plan/index/list',
        method: 'post',
        data: this.queryData,
      }).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      })
      this.isTableLoading = false;
    },
  },
};
</script>

<style scoped>
.head {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  background: #ffffff;
  border-radius: 5px;
  padding: 20px 20px 0;
}

.input {
  display: flex;
  align-items: center;
  margin-right: 15px;
  margin-bottom: 20px;
}

.input > span {
  font-size: 12px;
  flex-shrink: 0;
}

.btn {
  margin-bottom: 20px;
}

.box {
  width: 100%;
  background: #ffffff;
  border-radius: 5px;
  padding: 20px;
  margin-top: 20px;
}

.action {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.action span {
  color: #0256ff;
  font-size: 12px;
  cursor: pointer;
  margin: 0 8px;
}

.form {
  max-height: 58vh;
  overflow: auto;
}

.form /deep/ .el-form-item__label {
  line-height: 14px;
}

.flex {
  width: 100%;
  display: flex;
  align-items: center;
}

.link {
  color: #0256ff;
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: underline;
  margin-left: 10px;
  font-size: 12px;
}

.authorize_title {
  font-size: 12px;
  margin-bottom: 15px;
}
</style>
